unit EditSrvOrder;

interface

uses
  Winapi.Windows, Winapi.Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUIForm, uniLabel, jpeg, uniGUIBaseClasses, uniImage, DB,
  DBClient, ClientRowSet, uniButton, uniBitBtn, uniEdit, uniDBEdit,
  uniMultiItem, uniComboBox, uniDBComboBox, uniDBLookupComboBox, uniPanel,
  uniMemo, uniDBMemo, uniBasicGrid, uniDBGrid;

type
  TFrmEditSrvOrder = class(TUniForm)
    dsSheet: TDataSource;
    UniImage8: TUniImage;
    lbCaption: TUniLabel;
    btSave: TUniBitBtn;
    btClose: TUniBitBtn;
    UniPanel9: TUniPanel;
    UniPanel10: TUniPanel;
    cbCust: TUniDBLookupComboBox;
    edCustName: TUniDBEdit;
    UniPanel11: TUniPanel;
    UniPanel12: TUniPanel;
    edContactor: TUniDBEdit;
    UniPanel1: TUniPanel;
    UniPanel2: TUniPanel;
    edCustAddr: TUniDBEdit;
    UniPanel3: TUniPanel;
    UniPanel4: TUniPanel;
    edCustTel: TUniDBEdit;
    UniPanel5: TUniPanel;
    UniPanel6: TUniPanel;
    cbNode: TUniDBLookupComboBox;
    UniPanel7: TUniPanel;
    UniPanel8: TUniPanel;
    cbEmp: TUniDBLookupComboBox;
    UniBitBtn1: TUniBitBtn;
    UniPanel13: TUniPanel;
    UniPanel14: TUniPanel;
    edEmpTel: TUniDBEdit;
    UniPanel15: TUniPanel;
    UniPanel42: TUniPanel;
    edRemark: TUniDBMemo;
    UniPanel16: TUniPanel;
    UniPanel17: TUniPanel;
    edSheetNO: TUniDBEdit;
    UniPanel18: TUniPanel;
    UniPanel20: TUniPanel;
    edState: TUniDBEdit;
    UniPanel19: TUniPanel;
    UniPanel21: TUniPanel;
    edCrtDate: TUniDBEdit;
    crsSheet: TClientRowSet;
    crsSheetORDER_ID: TStringField;
    crsSheetORDER_NO: TStringField;
    crsSheetCATEGORY: TStringField;
    crsSheetPRODUCT_ID: TStringField;
    crsSheetPRODUCT_CODE: TStringField;
    crsSheetPRODUCT_NAME: TStringField;
    crsSheetCUST_ID: TStringField;
    crsSheetCUST_NO: TStringField;
    crsSheetCUST_NAME: TStringField;
    crsSheetCUST_MOBILE: TStringField;
    crsSheetCUST_ADDR: TStringField;
    crsSheetSOURCE_ACCOUNT: TStringField;
    crsSheetSYS_ACCOUNT: TStringField;
    crsSheetEMP_ID: TStringField;
    crsSheetEMP_NO: TStringField;
    crsSheetEMP_NAME: TStringField;
    crsSheetEMP_MOBILE: TStringField;
    crsSheetCREATE_DATE: TStringField;
    crsSheetACCEPT_DATE: TStringField;
    crsSheetEXECUTE_DATE: TStringField;
    crsSheetCLOSE_DATE: TStringField;
    crsSheetPLAN_DATE: TStringField;
    crsSheetPLAN_TIME: TStringField;
    crsSheetSTATE: TIntegerField;
    crsSheetUPDATETIME: TStringField;
    crsSheetDISABLED: TIntegerField;
    crsSheetVERSION: TIntegerField;
    crsSheetCOMMERCIAL_ID: TStringField;
    crsSheetREMARK: TStringField;
    crsSheetCOMMERCIAL_NO: TStringField;
    crsSheetCOMMERCIAL_NAME: TStringField;
    crsSheetSOURCE_COMPANY: TStringField;
    crsSheetCOMPANY: TStringField;
    crsSheetCOMP_TEL: TStringField;
    crsSheetASSIGN_DATE: TStringField;
    crsSheetPENDING_DATE: TStringField;
    crsSheetEMP_STATE: TIntegerField;
    crsSheetGROUP_CODE: TStringField;
    crsSheetNODE_NO: TStringField;
    crsSheetCUST_COMP: TStringField;
    crsSheetLKSTATE: TStringField;
    dsComp: TDataSource;
    dsNode: TDataSource;
    edEmpName: TUniDBEdit;
    dsEmp: TDataSource;
    UniBitBtn2: TUniBitBtn;
    crsNode: TClientRowSet;
    crsEmp: TClientRowSet;
    procedure btCloseClick(Sender: TObject);
    procedure btSaveClick(Sender: TObject);
    procedure cbCustCloseUp(Sender: TObject);
    procedure cbEmpCloseUp(Sender: TObject);
    procedure UniBitBtn2Click(Sender: TObject);
    procedure UniFormCreate(Sender: TObject);
    procedure cbNodeCloseUp(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

function FrmEditSrvOrder: TFrmEditSrvOrder;

implementation

{$R *.dfm}

uses
  MainModule, uniGUIApplication,DictModule,ExpModule,ToolModule,FindTruck,FindCust,uCommFunction,
  FindAddress, uSelectCust;

function FrmEditSrvOrder: TFrmEditSrvOrder;
begin
  Result := TFrmEditSrvOrder(UniMainModule.GetFormInstance(TFrmEditSrvOrder));
end;

procedure TFrmEditSrvOrder.btCloseClick(Sender: TObject);
begin
  TClientRowset(dsSheet.DataSet).CancelUpdates;
  self.Close;
end;

procedure TFrmEditSrvOrder.btSaveClick(Sender: TObject);
begin
  TClientRowset(dsSheet.DataSet).ApplyUpdates;
  self.Close;
end;

procedure TFrmEditSrvOrder.cbCustCloseUp(Sender: TObject);
var
  conid:String;
begin
  if dsComp.DataSet.RecordCount = 0 then exit;
  if dsComp.DataSet.FieldByName('COMP_NAME').AsString = '' then exit;
  dsSheet.DataSet.Edit;
  with dsSheet.DataSet do
  begin
    FieldByName('SOURCE_ACCOUNT').AsString  := dsComp.DataSet.FieldByName('XUNY_NO').AsString;
    FieldByName('CUST_COMP').AsString  := dsComp.DataSet.FieldByName('COMP_NAME').AsString;
    FieldByName('CUST_MOBILE').AsString   := dsComp.DataSet.FieldByName('TEL').AsString;
    FieldByName('CUST_NAME').AsString   := dsComp.DataSet.FieldByName('DEFAULT_CONTACTOR').AsString;
    FieldByName('CUST_ADDR').AsString   := dsComp.DataSet.FieldByName('ADDRESS').AsString;
  end;

end;

procedure TFrmEditSrvOrder.cbEmpCloseUp(Sender: TObject);
begin
  if dsEmp.DataSet.RecordCount = 0 then exit;
  if dsEmp.DataSet.FieldByName('EMP_NO').AsString = '' then exit;

  dsSheet.DataSet.Edit;
  with dsSheet.DataSet do
  begin
    FieldByName('EMP_NO').AsString   := dsEmp.DataSet.FieldByName('EMP_NO').AsString;
    FieldByName('EMP_NAME').AsString := dsEmp.DataSet.FieldByName('EMP_NAME').AsString;
    FieldByName('EMP_MOBILE').AsString  := dsEmp.DataSet.FieldByName('EMP_MOBILE').AsString;
  end;
end;

procedure TFrmEditSrvOrder.cbNodeCloseUp(Sender: TObject);
begin
  cbEmp.KeyValue := '';
  cbEmp.ItemIndex := -1;
  crsEmp.Filtered := False;
  if cbNode.Text <> '' then
  begin
    crsEmp.Filter := 'node_no=' + QuotedStr(VarToStr(cbNode.KeyValue)) + ' AND state<>1';
    crsEmp.Filtered := True;
  end;
end;

procedure TFrmEditSrvOrder.UniBitBtn2Click(Sender: TObject);
begin
  with FrmSelectCust do
  begin
    aType := 0;
    soModifyField.sourceAccount := dsSheet.DataSet.FieldByName('source_account');
    soModifyField.custComp := dsSheet.DataSet.FieldByName('cust_comp');
    soModifyField.custMobile := dsSheet.DataSet.FieldByName('cust_mobile');
    soModifyField.custName := dsSheet.DataSet.FieldByName('cust_name');
    soModifyField.custAddr := dsSheet.DataSet.FieldByName('cust_addr');
    ShowModal;
  end;
end;

procedure TFrmEditSrvOrder.UniFormCreate(Sender: TObject);
begin
  SetCompoentLanguage(Self);
  crsNode.Data := dmDict.crsNode.Data;
  crsEmp.Data := dmDict.crsEmployee.Data;
  crsEmp.Filter := 'state<>1';
  crsEmp.Filtered := True;
end;

end.
